<template>
  <div>
    <el-dialog
      title="密码编辑"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <el-form
        label-position="right"
        label-width="120px"
        :model="formLabelAlign"
      >
        <el-form-item label="旧密码：">
          <el-input v-model="formLabelAlign.oldPassword"></el-input>
        </el-form-item>
        <el-form-item label="新密码：">
          <el-input v-model="formLabelAlign.newPassword"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from "vuex";
import axios from "axios";
export default {
  components: {},
  props: {},
  data() {
    return {
      dialogVisible: false,
      formLabelAlign: {
        oldPassword: "",
        newPassword: "",
      },
    };
  },
  computed: {
    ...mapState({}),
  },
  watch: {},
  beforeDestroy() {},
  created() {},
  methods: {
    handleClose() {
      this.dialogVisible = false;
      this.$message({
        type: "warning",
        message: "已取消编辑",
      });
    },
    openDialog() {
      this.dialogVisible = true;
    },
    submit() {
      console.log(this.formLabelAlign);
      let password = this.formLabelAlign.newPassword;
      let id = localStorage.getItem("yh");
      let passWord = this.formLabelAlign.oldPassword;
      let ind = localStorage.getItem("lx");
      if (ind == "1") {
        axios
          .post("/api/user/updateteapassword", { password, id, passWord })
          .then((response) => {
            console.log(response);
            if (response.data.msg === "修改成功") {
              this.$message({
                type: "success",
                message: `${response.data.msg}`,
              });
              console.log(response.data);
              // location.reload();
              this.dialogVisible = false;
              this.$router.push("/");
            } else {
              this.$message({
                type: "warning",
                message: `${response.data.msg}`,
              });
            }
          })
          .catch(function (error) {
            console.log(error);
          });
      } else if (ind == "2") {
        axios
          .post("/api/user/updatestupassword", { password, id, passWord })
          .then((response) => {
            console.log(response);
            if (response.data.msg === "修改成功") {
              this.$message({
                type: "success",
                message: `${response.data.msg}`,
              });
              console.log(response.data);
              // location.reload();
              this.dialogVisible = false;
              this.$router.push("/");
            } else {
              this.$message({
                type: "warning",
                message: `${response.data.msg}`,
              });
            }
          })
          .catch(function (error) {
            console.log(error);
          });
      }
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.el-button {
  position: static !important;
}
/deep/ .el-dialog {
  .el-dialog__header {
    background: #143853 !important;
  }
  .el-dialog__title {
    color: #ffffff;
  }
  .el-dialog__body {
    color: #ffffff;
    padding-bottom: 20px;
    background: #0f2d43 !important;
  }
  .el-dialog__footer {
    padding-right: 40px;
    background: #0f2d43;
  }
  .el-form-item__label {
    color: #ffffff;
  }
  .el-input__inner {
    background: #0355a4 !important;
    border: none;
    color: #ffffff;
  }
}
</style>